/*1.业务逻辑(左侧加号展开阅读):
 * 	本程序用于用户访问首页，访问分为2种情况：
 *		1) 当用户首次访问该servlet时，跳转到登录界面
 *		2) 当用户再次访问该servlet时，直接跳转至首页
 *	当session过期，或用户自行退出登录时，再次跳转到登录界面。
 *
 *
 *2.实现逻辑：获取session中的用户对象
 *	1) 若未获取到，则说明用户首次访问该程序，未登录
 *	2) 若获取到，则说明用户已进行登录，直接访问主页
 * 
 */

package OSMS.action.User;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import com.sun.xml.internal.ws.resources.HttpserverMessages;

import OSMS.entity.Customers;
import OSMS.dao.*;
public class Cus_Index_Servlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		
//---------------------------1. 获取session检验是否首次访问 ----------------------------//
		HttpSession session = request.getSession();
		Object cus = null;
		cus = session.getAttribute("cus");

		
		
		if(cus != null) {//cus非空，则说明非首次访问，直接访问系统首页
			response.sendRedirect(request.getServletContext().getContextPath() + "/jsp/index/loadindex");
			return;
		}else{			 //cus为空，则说明首次访问，跳转至登录界面
			request.getRequestDispatcher("login.html").forward(request, response);
		}
	}
	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}

}
